﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using ZhaoXi_Core_WebApi.Utility;

namespace ZhaoXi_Core_WebApi.Controllers
{
    //webapi的控制器是严格遵循Restfull风格的
    [ApiController]
    [Route("[controller]")]
    public class FirstController : ControllerBase
    {


        private readonly ILogger<FirstController> _logger; //因为是注入嘛，所以默认情况 下是为空的

        public FirstController(ILogger<FirstController> logger)
        {
            _logger = logger;
            _logger.LogInformation("FirstController被构造了");
        }

        [HttpGet] //http://localhost:5000/First/
        public string get() 
        {
            return "dxf你是最棒的";
        }

        [HttpGet("{id},{name}")] //restful风格的请求参数要这么写 http://localhost:5000/First/1,a

        public string getname(int id, string name)
        {
            _logger.LogInformation("FirstController的getname被调用了");
            var xx = new { naem = "dxf", age = 24 };
            return Newtonsoft.Json.JsonConvert.SerializeObject(xx);
        }
    }
}